#include <QtUiTools\quiloader.h>
#include <QtCore\qfile.h>
#include <QtCore\qcoreapplication.h>

#include <maya\MArgList.h>
#include <maya\MArgDatabase.h>
#include <maya\MSyntax.h>
#include <maya\MFnPlugin.h>
#include <maya\MIOStream.h>
#include <maya\MString.h>
#include <maya\MGlobal.h>
#include <QtGui\qpushbutton.h>

#include <qtplugin.h>

#include <string>
#include <string.h>

//==============================================
//-->	QT WINDOW CLASS
//==============================================
qtTestUI::qtTestUI( QWidget* parent ) : QMainWindow( parent )
{
	// Initialize the UI and set this as its parent.
	setupUi( this );

	// Connect the button.
	connect( pushButton, SIGNAL(clicked()), this, SLOT(buttonPushed()));

	// Show it.
	show();
}

void qtTestUI::buttonPushed()
{
	MGlobal::displayWarning( "CLICK!" );
}

//==============================================
//-->	COMMAND CLASS
//==============================================
QPointer<qtTestUI> qtTest::qtTestWindow;

void qtTest::cleanup()
{
	if ( !qtTestWindow.isNull() )
	{
		delete qtTestWindow;
	}
}


MStatus qtTest::doIt( const MArgList& args )
{
	if ( qtTestWindow.isNull() )
	{
		qtTestWindow = new qtTestUI();
	}
	else
	{
		qtTestWindow->showNormal();
		qtTestWindow->raise();
	}

	return MS::kSuccess;
}

void* qtTest::creator()
{
	return new qtTest;
}


MSyntax qtTest::newSyntax()
{
	// Setup command flags.
	MSyntax syntax;

	return syntax;
}

MStatus qtTest::parseArgs( const MArgList& args )
{
	MStatus	status;

	// String used for debugging.
	MString	argDebug;

	// Get the flags.
	MArgDatabase argData( syntax(), args, &status );
	if ( !status )
		return status;

	return status;
}

MStatus initializePlugin( MObject obj )
{
	MStatus status;
	MFnPlugin plugin( obj, "ABaker", "1.0", "2014" );
	plugin.registerCommand( "qtTest", qtTest::creator, qtTest::newSyntax );
	
	if (!status)
	{
		status.perror( "Failed to register command" );
	}

	return status;
}

MStatus uninitializePlugin( MObject obj )
{
	MStatus status;
	MFnPlugin plugin( obj );
	plugin.deregisterCommand( "qtTest" );
	
	if (!status)
	{
		status.perror( "Failed to deregister command" );
	}

	return status;
}